prepare("SELECT * FROM students WHERE id = ?"); $stmt->execute([$_SESSION['student_id']]); $student = $stmt->fetch(PDO::FETCH_ASSOC); // Handle profile update $update_success = false; $errors = []; if ($_SERVER['REQUEST_METHOD'] === 'POST') { $full_name = trim($_POST['full_name']); $email = trim($_POST['email']); $phone = trim($_POST['phone']); // Basic validation if (empty($full_name)) { $errors[] = "Full name is required"; } if (empty($email)) { $errors[] = "Email is required"; } elseif (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $errors[] = "Invalid email format"; } // Check if email already exists (excluding current student) $stmt = $pdo->prepare("SELECT id FROM students WHERE email = ? AND id != ?"); $stmt->execute([$email, $_SESSION['student_id']]); if ($stmt->fetch()) { $errors[] = "Email already exists"; } if (empty($errors)) { // Update student profile $stmt = $pdo->prepare("UPDATE students SET full_name = ?, email = ?, phone = ?, updated_at = NOW() WHERE id = ?"); if ($stmt->execute([$full_name, $email, $phone, $_SESSION['student_id']])) { $update_success = true; // Refresh student data $stmt = $pdo->prepare("SELECT * FROM students WHERE id = ?"); $stmt->execute([$_SESSION['student_id']]); $student = $stmt->fetch(PDO::FETCH_ASSOC); } else { $errors[] = "Failed to update profile. Please try again."; } } } // Get student statistics $stmt = $pdo->prepare(" SELECT COUNT(DISTINCT es.exam_id) as total_exams_taken, COUNT(r.id) as total_attempts, AVG(r.percentage) as average_score, MAX(r.percentage) as best_score FROM exam_sessions es JOIN results r ON es.id = r.session_id WHERE es.student_id = ? "); $stmt->execute([$_SESSION['student_id']]); $stats = $stmt->fetch(PDO::FETCH_ASSOC); // Get exam history $stmt = $pdo->prepare(" SELECT e.name as exam_name, e.year, s.name as subject_name, r.correct_answers, r.total_questions, r.percentage, r.submitted_at FROM results r JOIN exam_sessions es ON r.session_id = es.id JOIN exams e ON es.exam_id = e.id JOIN subjects s ON e.subject_id = s.id WHERE es.student_id = ? ORDER BY r.submitted_at DESC LIMIT 10 "); $stmt->execute([$_SESSION['student_id']]); $exam_history = $stmt->fetchAll(PDO::FETCH_ASSOC); ?>
Manage your account information and track your progress
| Exam | Subject | Score | Percentage | Date |
|---|---|---|---|---|
| / | = 80) $score_class = 'score-excellent'; elseif ($percentage >= 60) $score_class = 'score-good'; elseif ($percentage < 40) $score_class = 'score-poor'; ?> % |
No exam history yet. Start your first exam to see your results here!